package com.itheima.dao;

import com.itheima.daomain.User;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @Descriptionn:test
 * @Create by:依然
 * @Date:2021/11/2 16:20
 */

/**
 * 功能:查询查询状态等于0的用户信息
 */
public interface UserMapper {
    @Select("SELECT id,name,sex,age,address,qq,email FROM t_user WHERE isdelete=0")
    List<User> SelectAll();





    /**
     * @param name
     * @param sex
     * @param age
     * @param address
     * @param qq
     * @param email
     * @return 添加用户信息
     */
    @Insert("INSERT INTO t_user (name,sex,age,address,qq,email) " +
            "VALUE(#{name},#{sex},#{age},#{address},#{qq},#{email})")
    public Integer interuser(
            @Param("name") String name,
            @Param("sex") String sex,
            @Param("age") Integer age,
            @Param("address") String address,
            @Param("qq") String qq,
            @Param("email") String email);


    /**
     * 根据id逻辑删除用户信息
     *
     * @param id
     * @return
     */
    @Update("UPDATE  t_user SET isdelete = 1 WHERE  id = #{id}")
    public Integer delect(int id);


    /**
     * 根据id修改用户信息
     *
     * @param user
     * @return
     */
    @Update("UPDATE t_user SET name=#{name},sex=#{sex},age=#{age},address=#{address} WHERE id=#{id}")
    public Integer update(User user);


    /**
     * 根据id查询用户的信息
     *
     * @param id
     * @return
     */
    @Select("SELECT id,name,sex,age,address,qq,email FROM t_user WHERE id=#{id}")
    public User selects(int id);


    @Select("SELECT * FROM t_user WHERE isdelete=0 LIMIT #{id},5")
    public List<User> selectpage(int id);

    /**
     * 模糊查询信息
     * @param keyword
     * @return
     */
    @Select("select id,name,sex,age,address,qq,email " +
            "from t_user " +
            "where name like concat('%',#{keyword},'%')  " +
            "or sex = #{keyword} " +
            "or qq like concat('%',#{keyword},'%') " +
            "or address = #{keyword} " +
            "or email like concat('%',#{keyword},'%')")
    public List<User> selectLike(String keyword);

}
